<template>
  <div class="EquipmentHmPg">
    <!-- 筛选 --start-->
    <div class="search">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input v-model="formInline.key" placeholder="请输入设备名称"></el-input>
        </el-form-item>
        <el-form-item label="输入时间">
          <el-date-picker
            v-model="formInline.time1"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="chage"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onsubmit">查询</el-button>
        </el-form-item>
      </el-form>
      <el-button class="ebtn" type="warning" @click="newmoj">新增模具</el-button>
    </div>
    <!-- 筛选 --end-->
    <div class="ProductionmanageList">
      <el-table :data="tableData" height="600px" stripe>
        <el-table-column prop="xuhao" label="序号" width="100px" align="center"></el-table-column>
        <el-table-column prop="equipmenttype" label="设备型号" align="center"></el-table-column>
        <el-table-column prop="equipmentname" label="设备名称" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productionon" label="生产日期" align="center"></el-table-column>
        <el-table-column prop="producers" label="生产商" align="center"></el-table-column>
        <el-table-column prop="address" label="设备位置" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="nextmaintenanceon" label="下次保养" align="center"></el-table-column>
        <el-table-column prop="state" label="状态" align="center"></el-table-column>
      </el-table>
    </div>
    <div class="pgnt">
      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="current"
        :page-size="pagesize"
        @current-change="handleCurrentChange"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      tableData: [],
      form: {},
      index: 2,
      formInline: {
        key: ""
      },
      start: "",
      end: "",
      total: 1,
      current: 1,
      pagesize: 10
    };
  },
  created() {
    this.getlist(0);
    this.Getlist();
  },
  methods: {
    // 新增页面跳转
    newmoj() {
      this.$router.push("/NewMoJu");
    },
    // // 编辑页面跳转
    // Edit() {
    //   this.$router.push("/QuipmentBianj");
    // },
    // // 详情页面跳转
    // Detail(e) {
    //   this.$router.push({
    //     path: "./QuipmentXiangq",
    //     query: { name: e }
    //   });
    // },
    // 列表
    getlist(page) {
      var obj = {
        start: this.start,
        end: this.end,
        key: this.formInline.key,
        pn: page,
        PerPageSize: 10
      };
      var objs = JSON.stringify(obj);
      axios(
        "/apis/DeviceManagement.asmx/List_Device?index=" +
          this.index +
          "&jsondata=" +
          objs
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        console.log("字符串");
        console.log(datas);
        var list = JSON.parse(datas.string.__text);
        console.log(list);
        this.tableData = list;
        for (var i = 0; i < list.length; i++) {
          this.tableData[i].xuhao = 1 + i + 10 * page;
        }
        for (var i = 0; i < list.length; i++) {
          var dd = new Date(parseInt(list[i].productionon.substr(6, 13)));
          var y = dd.getFullYear();
          var m = dd.getMonth() + 1;
          m = m < 10 ? "0" + m : m;
          var d = dd.getDate();
          d = d < 10 ? "0" + d : d;
          list[i].productionon = y + "-" + m + "-" + d;
          var ddd = new Date(parseInt(list[i].nextmaintenanceon.substr(6, 13)));
          var y = ddd.getFullYear();
          var m = ddd.getMonth() + 1;
          m = m < 10 ? "0" + m : m;
          var d = ddd.getDate();
          d = d < 10 ? "0" + d : d;
          list[i].nextmaintenanceon = y + "-" + m + "-" + d;
        }
      });
    },
    Getlist() {
      var obj = {
        start: "",
        end: "",
        key: this.formInline.key,
        pn: 0,
        PerPageSize: 10000
      };
      var objs = JSON.stringify(obj);
      axios(
        "/apis/DeviceManagement.asmx/List_Device?index=" +
          this.index +
          "&jsondata=" +
          objs
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        var list = JSON.parse(datas.string.__text);
        this.total = list.length;
      });
    },
    // 分页
    handleCurrentChange(e) {
      this.getlist(e - 1);
    },
    // 日期改变
    chage(e) {
      console.log("e");
      console.log(e);
      if (e) {
        this.start =
          e[0].getFullYear() +
          "-" +
          (e[0].getMonth() + 1) +
          "-" +
          e[0].getDate();
        this.end =
          e[1].getFullYear() +
          "-" +
          (e[1].getMonth() + 1) +
          "-" +
          e[1].getDate();
      } else {
        this.start = "";
        this.end = "";
      }
    },
    // 筛选
    onsubmit() {
      console.log("e");
      this.getlist(0);
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";
.EquipmentHmPg {
  width: 99%;
  // height: 500px;
  margin-top: 20px;
}

.ProductionmanageList {
  width: 99%;
  // height: 300px;
  margin-top: 20px;
  margin-left: 15px;
  background-color: $white;
  border: 1px solid $linecolor;
  // max-height: 400px;
}
.search {
  height: 50px;
  border-radius: 5px;
  background-color: #fff;
  padding-left: 20px;
  padding-top: 10px;
  margin-bottom: 20px;
  width: 97.5%;
  margin-left: 15px;
}
.ebtn {
  float: right;
  margin-right: 20px;
  // margin-top: -63px;
}
.pgnt {
  text-align: center;
}
.demo-form-inline {
  display: inline-block;
}
</style>